package com.ttdevs.tvolley;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;

import com.lidroid.xutils.exception.HttpException;
import com.ttdevs.tvolley.util.file.FileLoadListener;
import com.ttdevs.tvolley.util.file.UUFileLoad;

public class FileUploadActivity extends Activity implements OnClickListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_file_upload);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btUpload:
			uploadFile();
			break;
		case R.id.btDownload:
			downloadFile();
			break;

		default:
			break;
		}
	}

	private void downloadFile() {
		
		String url = "https://dl.google.com/pinyin/v2/GooglePinyinInstaller.exe";
		String target = Environment.getExternalStorageDirectory() + "/aaaaa/GooglePinyinInstaller.exe";
		UUFileLoad uufl = UUFileLoad.getInstance();
		uufl.download(url, target, new FileLoadListener() {
			
			@Override
			public void onLoading(long total, long current) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onFailure(HttpException he) {
				// TODO Auto-generated method stub
				
			}
		});
		// uufl.cancel();
	}

	private void uploadFile() {
		String url = "http://192.168.9.80:8888/Umarket/mdisplay/add";
		String target = Environment.getExternalStorageDirectory() + "/aaaaa/GooglePinyinInstaller.exe";
		
		UUFileLoad uufl = UUFileLoad.getInstance();
		uufl.upload(url, new FileLoadListener() {
			
			@Override
			public void onLoading(long total, long current) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onFailure(HttpException he) {
				// TODO Auto-generated method stub
				
			}
		});
	}
}
